package vip.source.pattern.part14.command;

import org.junit.jupiter.api.Test;
import vip.source.pattern.part14.command.domain.Light;
import vip.source.pattern.part14.command.service.Command;
import vip.source.pattern.part14.command.service.impl.LightOffCommand;
import vip.source.pattern.part14.command.service.impl.LightOnCommand;

/**
 * @Description: 测试命令模式
 * @Author: zy
 **/
public class UnitTest {
    @Test
    public void test() {
        Light light = new Light();
        Command lightOn = new LightOnCommand(light);
        Command lightOff = new LightOffCommand(light);

        RemoteControl remote = new RemoteControl();

        // 按下打开灯的按钮
        remote.setCommand(lightOn);
        remote.pressButton();

        // 按下关闭灯的按钮
        remote.setCommand(lightOff);
        remote.pressButton();
    }
}
